home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / util / logging / Handler.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  4.7 KB  |  154 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  Handler.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.UTIL.LOGGING.Handler"))
  26. {   
  27.   /****h* NOF_JavaScript_Library/NOF.UTIL.LOGGING.Handler
  28.     *
  29.     * NAME
  30.     *  NOF.UTIL.LOGGING.Handler
  31.     *
  32.     * DESCRIPTION
  33.     *  
  34.     * Base class for Logger's <code>Handler</code> objects.
  35.     * A Handler has a minimum level for records to be processed,
  36.     * has a Formatter to format the message and 
  37.     * a filter which can be use to enable or disable the processing 
  38.     * of the log records sent to this Handler.
  39.     * Default formatter is a LOGGING.Formatter object and 
  40.     * default filter is a LOGGING.Filter. The Handler is initialized to 
  41.     * process all the messages (level set to LOGGING.Level.FINEST).
  42.     * This Handler will finally call the javascript alert() after 
  43.     * processing the log record.
  44.     * 
  45.     * @see <code>ConsoleHandler</code>
  46.     *
  47.     * External dependencies: 
  48.     ****/
  49.   
  50.   /**
  51.   * constructor 
  52.   * @param logger instance of the Logger who "owns" this Handler
  53.   **/
  54.   function LOGGING_Handler( logger ) {
  55.     this.__proto__ = LOGGING_Handler.prototype;    
  56.     
  57.     this.logger = logger;
  58.     
  59.     this.level = LOGGING.Level.FINEST;
  60.     this.filter = new LOGGING.Filter();
  61.     this.formatter = new LOGGING.Formatter();
  62.   }
  63.   {
  64.     var member = LOGGING_Handler.prototype;    
  65.     member.CLASS_NAME        = "LOGGING.Handler";
  66.  
  67.     var method = LOGGING_Handler.prototype;     
  68.     
  69.     /**
  70.     * Output the processed string (this implementation is just firing an alert).
  71.     * Subclasses can only overwrite this method to notify other media 
  72.     * with the processed message 
  73.     *     
  74.     * @param str message string 
  75.     **/
  76.     method.output = function (/*string*/ str) {
  77.         var nofAlertEnabled = IS_isModuleInitialized("IS.NOF.DIALOGS.Messages");
  78.         if (!nofAlertEnabled) {
  79.             NOF.loadClasses(NOF.App.getSystemDirectory() + "FSI/",
  80.                 "lib/nof/dialogs/Messages");
  81.             nofAlertEnabled = IS_isModuleInitialized("IS.NOF.DIALOGS.Messages");
  82.         }
  83.         if (nofAlertEnabled) {
  84.             NOF.DIALOGS.Messages.alert(str, this.logger.getLoggerName(), "OK", null, 300, 400);
  85.         } else {
  86.             alert(str);
  87.         }
  88.     }
  89.     
  90.     /**
  91.     * Determine if a record will be processed by this Handler.
  92.     * 
  93.     * @param logRecord
  94.     * @return true if the level of logRecord is less or equal than this Handler's level.
  95.     **/
  96.     method.isLoggable    = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) { 
  97.       return ( (this.level >= logRecord.getLevel()) && this.filter.isLoggable(logRecord) ); 
  98.     }
  99.     
  100.     /**
  101.     * publish the log record. If the log record is loggable, output the formated string 
  102.     * returned by the associated formatter.
  103.     * @param logRecord
  104.     **/
  105.     method.publish = function (/*NOF.UTIL.LOGGING.LogRecord*/ logRecord) { 
  106.       if (this.isLoggable(logRecord)) {
  107.         var ft = this.formatter.format(logRecord); 
  108.         this.output(ft);                             
  109.       }
  110.     }        
  111.     
  112.     /**
  113.     * Set a new Formatter
  114.     *
  115.     * @param nFormatter
  116.     **/
  117.     method.setFormatter = function (/*NOF.UTIL.LOGGING.Formatter*/ nFormatter) { this.formatter = nFormatter; }
  118.     
  119.     /**
  120.     * Get the Formatter associated to this Handler
  121.     *
  122.     * @return the Formatter of the Handler
  123.     **/        
  124.     method.getFormatter = function () { return this.formatter; }
  125.  
  126.     /**
  127.     * Set a new Filter
  128.     *
  129.     * @param nFilter
  130.     **/        
  131.     method.setFilter = function (/*NOF.UTIL.LOGGING.Filter*/ nFilter) { this.filter = nFilter; }
  132.     
  133.     /**
  134.     * Get the Filter associated to this Handler
  135.     *
  136.     * @return the Filter of the Handler
  137.     **/                
  138.     method.getFilter = function () { return this.filter; }
  139.     
  140.     /**
  141.     * Set the minumum level from which the records passed to this Handler should be processed
  142.     * @param level one of the values defined by LOGGING.Level interface
  143.     **/        
  144.     method.setLevel = function (/*NOF.UTIL.LOGGING.Level*/ level) { this.level = level; }
  145.     
  146.     /**
  147.     * Get the minimum log level from which the records passed to this Handler will be processed.
  148.     * @return level
  149.     **/        
  150.     method.getLevel = function () { return this.level; }    
  151.   }
  152.   
  153.   LOGGING.__proto__.Handler = LOGGING_Handler;
  154. }